<template>
  <div class="app-container">
	  
	<el-dialog v-model="dialogVisible" title="卡次使用记录" width="50%" destroy-on-close>  
		<el-table style="height: calc(100vh - 330px);" size="small" v-loading="loading" :data="countRecordList" @selection-change="handleSelectionChange">
		  <el-table-column type="index" title="序号" width="55" align="center" />
		  <!-- <el-table-column label="ID" align="center" prop="id" /> -->
		  <!-- <el-table-column label="关联ID" align="center" prop="saleId" /> -->
		  <el-table-column label="使用时间" align="center" prop="userTime" width="180">
			<template #default="scope">
			  <span>{{ parseTime(scope.row.userTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
			</template>
		  </el-table-column>
		  <el-table-column label="使用前计数" align="center" prop="beforeUseNum" />
		  <el-table-column label="使用数量" align="center" prop="useNum" />
		  <el-table-column label="使用后计数" align="center" prop="afterUseNum" />
		  <el-table-column label="备注" align="center" prop="remark" width="120" show-overflow-tooltip/>
		</el-table>
    
		<pagination
		  v-show="total>0"
		  :total="total"
		  v-model:page="queryParams.pageNum"
		  v-model:limit="queryParams.pageSize"
		  @pagination="getList"
		/>
	
	</el-dialog>
  </div>
</template>

<script setup name="CountRecord">
import { listCountRecord, getCountRecord, delCountRecord, addCountRecord, updateCountRecord } from "@/api/crm/countRecord";

const { proxy } = getCurrentInstance();

const countRecordList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);



const dialogVisible = ref(false);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
	orderByColumn:'userTime',
	isAsc:'desc',
    saleId: null,
    userTime: null,
    beforeUseNum: null,
    useNum: null,
    afterUseNum: null,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);


function openWin(saleId){
	queryParams.value.saleId = saleId;
	
	dialogVisible.value = true;
	getList();
}

/** 查询次卡使用记录列表 */
function getList() {
  loading.value = true;
  listCountRecord(queryParams.value).then(response => {
    countRecordList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    saleId: null,
    userTime: null,
    beforeUseNum: null,
    useNum: null,
    afterUseNum: null,
    remark: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  proxy.resetForm("countRecordRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}


defineExpose({
	openWin
})
</script>
